
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/14/2013 13:11:11
-- Generated from EDMX file: D:\Datamatiker\3.Semester\mini\Programmer\Opskrift\Opskrift\OpskriftModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [alaborg_dk_db];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Ingrediens_KategoriIngredienser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IngredienserSet] DROP CONSTRAINT [FK_Ingrediens_KategoriIngredienser];
GO
IF OBJECT_ID(N'[dbo].[FK_Opskrift_KategoriOpskrift]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OpskriftSet] DROP CONSTRAINT [FK_Opskrift_KategoriOpskrift];
GO
IF OBJECT_ID(N'[dbo].[FK_MaaleEnhedIngredienser_Opskrift]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Ingredienser_OpskriftSet] DROP CONSTRAINT [FK_MaaleEnhedIngredienser_Opskrift];
GO
IF OBJECT_ID(N'[dbo].[FK_IngredienserIngredienser_Opskrift]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Ingredienser_OpskriftSet] DROP CONSTRAINT [FK_IngredienserIngredienser_Opskrift];
GO
IF OBJECT_ID(N'[dbo].[FK_OpskriftIngredienser_Opskrift]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Ingredienser_OpskriftSet] DROP CONSTRAINT [FK_OpskriftIngredienser_Opskrift];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[IngredienserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IngredienserSet];
GO
IF OBJECT_ID(N'[dbo].[Ingrediens_KategoriSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Ingrediens_KategoriSet];
GO
IF OBJECT_ID(N'[dbo].[OpskriftSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OpskriftSet];
GO
IF OBJECT_ID(N'[dbo].[Opskrift_KategoriSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Opskrift_KategoriSet];
GO
IF OBJECT_ID(N'[dbo].[MaaleEnhedSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MaaleEnhedSet];
GO
IF OBJECT_ID(N'[dbo].[Ingredienser_OpskriftSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Ingredienser_OpskriftSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'IngredienserSet'
CREATE TABLE [dbo].[IngredienserSet] (
    [ingrediens_Id] int IDENTITY(1,1) NOT NULL,
    [pris] decimal(18,0)  NOT NULL,
    [Ingrediens_Kategori_kategori_Id] int  NOT NULL,
    [beskrivelse] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Ingrediens_KategoriSet'
CREATE TABLE [dbo].[Ingrediens_KategoriSet] (
    [kategori_Id] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'OpskriftSet'
CREATE TABLE [dbo].[OpskriftSet] (
    [opskrift_Id] int IDENTITY(1,1) NOT NULL,
    [Navn] nvarchar(max)  NOT NULL,
    [Opskrift_KategoriId] int  NOT NULL,
    [kogeTid] float  NOT NULL,
    [feskrivelse] nvarchar(max)  NOT NULL,
    [fremgangsMaade] nvarchar(max)  NOT NULL,
    [totalPris] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'Opskrift_KategoriSet'
CREATE TABLE [dbo].[Opskrift_KategoriSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [type] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'MaaleEnhedSet'
CREATE TABLE [dbo].[MaaleEnhedSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [navn] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Ingredienser_OpskriftSet'
CREATE TABLE [dbo].[Ingredienser_OpskriftSet] (
    [antal] float  NOT NULL,
    [MaaleEnhedId] int  NOT NULL,
    [Ingredienser_ingrediens_Id] int  NOT NULL,
    [Opskrift_opskrift_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ingrediens_Id] in table 'IngredienserSet'
ALTER TABLE [dbo].[IngredienserSet]
ADD CONSTRAINT [PK_IngredienserSet]
    PRIMARY KEY CLUSTERED ([ingrediens_Id] ASC);
GO

-- Creating primary key on [kategori_Id] in table 'Ingrediens_KategoriSet'
ALTER TABLE [dbo].[Ingrediens_KategoriSet]
ADD CONSTRAINT [PK_Ingrediens_KategoriSet]
    PRIMARY KEY CLUSTERED ([kategori_Id] ASC);
GO

-- Creating primary key on [opskrift_Id] in table 'OpskriftSet'
ALTER TABLE [dbo].[OpskriftSet]
ADD CONSTRAINT [PK_OpskriftSet]
    PRIMARY KEY CLUSTERED ([opskrift_Id] ASC);
GO

-- Creating primary key on [Id] in table 'Opskrift_KategoriSet'
ALTER TABLE [dbo].[Opskrift_KategoriSet]
ADD CONSTRAINT [PK_Opskrift_KategoriSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MaaleEnhedSet'
ALTER TABLE [dbo].[MaaleEnhedSet]
ADD CONSTRAINT [PK_MaaleEnhedSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Ingredienser_ingrediens_Id], [Opskrift_opskrift_Id] in table 'Ingredienser_OpskriftSet'
ALTER TABLE [dbo].[Ingredienser_OpskriftSet]
ADD CONSTRAINT [PK_Ingredienser_OpskriftSet]
    PRIMARY KEY CLUSTERED ([Ingredienser_ingrediens_Id], [Opskrift_opskrift_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Ingrediens_Kategori_kategori_Id] in table 'IngredienserSet'
ALTER TABLE [dbo].[IngredienserSet]
ADD CONSTRAINT [FK_Ingrediens_KategoriIngredienser]
    FOREIGN KEY ([Ingrediens_Kategori_kategori_Id])
    REFERENCES [dbo].[Ingrediens_KategoriSet]
        ([kategori_Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Ingrediens_KategoriIngredienser'
CREATE INDEX [IX_FK_Ingrediens_KategoriIngredienser]
ON [dbo].[IngredienserSet]
    ([Ingrediens_Kategori_kategori_Id]);
GO

-- Creating foreign key on [Opskrift_KategoriId] in table 'OpskriftSet'
ALTER TABLE [dbo].[OpskriftSet]
ADD CONSTRAINT [FK_Opskrift_KategoriOpskrift]
    FOREIGN KEY ([Opskrift_KategoriId])
    REFERENCES [dbo].[Opskrift_KategoriSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Opskrift_KategoriOpskrift'
CREATE INDEX [IX_FK_Opskrift_KategoriOpskrift]
ON [dbo].[OpskriftSet]
    ([Opskrift_KategoriId]);
GO

-- Creating foreign key on [MaaleEnhedId] in table 'Ingredienser_OpskriftSet'
ALTER TABLE [dbo].[Ingredienser_OpskriftSet]
ADD CONSTRAINT [FK_MaaleEnhedIngredienser_Opskrift]
    FOREIGN KEY ([MaaleEnhedId])
    REFERENCES [dbo].[MaaleEnhedSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MaaleEnhedIngredienser_Opskrift'
CREATE INDEX [IX_FK_MaaleEnhedIngredienser_Opskrift]
ON [dbo].[Ingredienser_OpskriftSet]
    ([MaaleEnhedId]);
GO

-- Creating foreign key on [Ingredienser_ingrediens_Id] in table 'Ingredienser_OpskriftSet'
ALTER TABLE [dbo].[Ingredienser_OpskriftSet]
ADD CONSTRAINT [FK_IngredienserIngredienser_Opskrift]
    FOREIGN KEY ([Ingredienser_ingrediens_Id])
    REFERENCES [dbo].[IngredienserSet]
        ([ingrediens_Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Opskrift_opskrift_Id] in table 'Ingredienser_OpskriftSet'
ALTER TABLE [dbo].[Ingredienser_OpskriftSet]
ADD CONSTRAINT [FK_OpskriftIngredienser_Opskrift]
    FOREIGN KEY ([Opskrift_opskrift_Id])
    REFERENCES [dbo].[OpskriftSet]
        ([opskrift_Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OpskriftIngredienser_Opskrift'
CREATE INDEX [IX_FK_OpskriftIngredienser_Opskrift]
ON [dbo].[Ingredienser_OpskriftSet]
    ([Opskrift_opskrift_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------